import { defineConfig, mergeConfig } from "vite";
import react from "@vitejs/plugin-react";
import vue from "@vitejs/plugin-vue";
// import { resolve } from "path";
import baseConfig from "./config/vite.config.base";
import { createHtmlPlugin } from "vite-plugin-html";
import { visualizer } from "rollup-plugin-visualizer";
import VitePluginCompression from "vite-plugin-compression";
// import vitePluginUploadOss from "vite-plugin-upload-oss";
// import ossConfig from "./config/oss.config";
// import uploader from "vite-plugin-aliyun-oss";

const isDev = process.env.NODE_ENV === "development";

// https://vitejs.dev/config/
const config = defineConfig({
	base: isDev ? "/" : "/pro/fdo",
	plugins: [
		react(),
		vue(),
		createHtmlPlugin({
			pages: [
				{
					entry: "./src/main.jsx",
					filename: "index.html",
					template: "index.html",
					injectOptions: {
						data: {
							injectScript: `<script type="module" src="/src/main.jsx"></script>`,
						},
					},
				},
			],
		}),
		visualizer({ open: true, gzipSize: true, brotliSize: true }),
		VitePluginCompression({
			threshold: 1024 * 300,
		}),
		// {
		//   ...uploader({ ...ossConfig }),
		// },
	],
	build: {
		rollupOptions: {
			output: {
				manualChunks: {
					"react-vender": ["react-dom", "react", "antd"],
					"vue-render": ["vue", "ant-design-vue"],
					// "highlight-render": ["react-syntax-highlighter"],
				},
			},
		},
	},
});

export default mergeConfig(baseConfig, config);
